import initData from '../../state_static'
function shoppingCarReduer(state=initData.shoppingCar,action){
    switch(action.type){
        case 'ADD_LISTS':
            let list=action.item;
            let exist=false;
            let newItems=state.items.map((item,index)=>{
               
                if(item.id===list.id){
                    exist=true;
                    return{...list,count:item.count+1};
                }else{
                    return item
                }
            })
            if(!exist){
                newItems.push({...list,count:1})
            }
            return{...state,items:newItems}
            default:return state;
    }
}

export default shoppingCarReduer